#include "main.h"


/**
*  Instantiates the \c MatrixBenchmark class.
*  \version 1.0.0a
*  \date    10 February 2011
*/
MatrixBenchmark::MatrixBenchmark()
{
}


/*void MatrixBenchmark::test_data()
 {
     QTest::addColumn<unsigned char>("dimensions");
     QTest::newRow("2D") << (unsigned char)2;
     QTest::newRow("4D") << (unsigned char)4;
 }*/


/**
*  Instantiates an empty 2D matrix.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkEmptyMatrix()
{
    QBENCHMARK{ Matrix<double,unsigned char,2> A; }
}


/**
*  Instantiates a 2D 3x3 matrix.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkMatrix()
{
    QBENCHMARK{ Matrix(A,double,unsigned char,2) {3,3} End; }
}


/**
*  Instantiates the copy of a 2D 3x3 matrix.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkCopyMatrix()
{
    Matrix(A,double,unsigned char,2) {3,3} End;
    QBENCHMARK{ Matrix<double,unsigned char,2> B(A); }
}


/**
*  Accesses the data of a 2D 3x3 matrix using a single index.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkDataAccessBySingleIndex_Matrix()
{
    Matrix(A,double,unsigned char,2) {3,3} End;
    double b;
    unsigned char i;

    for( i = 0; i < 9; i++ )
    {
        QBENCHMARK{ b = A(i); }
    }
}


/**
*  Accesses the data of an array of length 9 using a single index.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkDataAccessBySingleIndex_Array()
{
    double *A = new double[9];
    double b;
    unsigned char i;

    for( i = 0; i < 9; i++ )
    {
        QBENCHMARK{ b = A[i]; }
    }

    delete [] A;
}


/**
*  Accesses the data of a 2D 3x3 matrix using two indices.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkDataAccessByTwoIndices_Matrix()
{
    Matrix(A,double,unsigned char,2) {3,3} End;
    double b;
    unsigned char i, j;

    for( i = 0; i < 3; i++ )
    {
        for( j = 0; j < 3; j++ )
        {
            QBENCHMARK{ b = A(i,j); }
        }
    }
}


/**
*  Accesses the data of an array of length 9 using two indices.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkDataAccessByTwoIndices_Array()
{
    double *A = new double[9];
    double b;
    unsigned char i, j;

    for( i = 0; i < 3; i++ )
    {
        for( j = 0; j < 3; j++ )
        {
            QBENCHMARK{ b = A[3*i+j]; }
        }
    }

    delete [] A;
}


/**
*  Assigns a 2D 3x3 matrix to a 2D 3x3 matrix.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkAssignmentMatrix()
{
    Matrix(A,double,unsigned char,2) {3,3} End;
    Matrix(B,double,unsigned char,2) {3,3} End;
    QBENCHMARK{ A = B; }
}


/**
*  Assigns an array of length 9 to an array of length 9.
*  \version 1.0.0a
*  \date    10 February 2011
*/
void MatrixBenchmark::benchmarkAssignmentArray()
{
    double *A = new double[9],
           *B = new double[9];
    unsigned char i;

    QBENCHMARK{
        for( i = 0; i < 9; i++ )
        {
            A[i] = B[i];
        }
    }

    delete [] A;
    delete [] B;
}
